//-----------------------------------------------------------------------
//<copyright file="DongMoKyDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
	public class DongMoKyDAO : SQLDatabase, IDongMoKyDAO
	{

		#region Create DongMoKy methods

		public DongMoKy CreateDongMoKy(DongMoKy dongMoKy)
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spDongMoKyInsert");
				AddOutParameter(command, "@MaKy", SqlDbType.NVarChar, dongMoKy.MaKy);
				AddInParameter(command, "@NgayMoKy", SqlDbType.DateTime, dongMoKy.NgayMoKy);
                AddInParameter(command, "@NgayDongKy", SqlDbType.DateTime, dongMoKy.NgayDongKy);

				ExecuteNonQuery(command);
				return dongMoKy;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access CreateDongMoKyException", ex);
			}
		}

		#endregion

		#region Update DongMoKy methods

		public void UpdateDongMoKy(DongMoKy dongMoKy)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spDongMoKyUpdate");

				AddInParameter(command, "@MaKy", SqlDbType.NVarChar, dongMoKy.MaKy);
                AddInParameter(command, "@DongKy", SqlDbType.Bit, dongMoKy.DongKy);
				AddInParameter(command, "@NguoiCapNhap", SqlDbType.NVarChar, dongMoKy.NguoiCapNhap);
				AddInParameter(command, "@GhiChu", SqlDbType.NVarChar, dongMoKy.GhiChu);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access UpdateDongMoKyException", ex);
			}
		}

		#endregion

		#region Delete DongMoKy methods

		public void DeleteDongMoKy(DongMoKy dongMoKy)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spDongMoKyDelete");

				AddInParameter(command, "@MaKy", SqlDbType.NVarChar, dongMoKy.MaKy);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access DeleteDongMoKyException", ex);
			}
		}

		#endregion

		#region Select methods

		#region GetAll DongMoKy methods

		public DongMoKies GetAllDongMoKy()
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spDongMoKyGetList");
				DongMoKies Result = new DongMoKies();
				List<DongMoKy> List = ExecuteQuery<DongMoKy>(command,true);
				foreach(DongMoKy item in List)
				{
					Result.Add(item);
				}
				return Result;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetAllDongMoKyException", ex);
			}
		}

		#endregion


		#region GetDongMoKy methods

		public DongMoKy GetDongMoKyByID(string maKy)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spDongMoKyGet");

				AddInParameter(command, "@maKy", SqlDbType.NVarChar, maKy);

				return ExecuteQuery<DongMoKy>(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetDongMoKyBy ID Exception", ex);
			}
		}

		#endregion


		#endregion
	}
}//End Class
